<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <link rel="stylesheet" href="../css/pagination.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script type="text/javascript" src="../js/jquery.pagination.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body class="layui-anim layui-anim-up">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input type="text" name="searchname"  placeholder="请输入公告标题" autocomplete="off" class="layui-input" id="searchname">
          <input type="text" name="searchid"  placeholder="请输入发布人ID" autocomplete="off" class="layui-input" id="searchid">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach" id="searchbutton"><i class="layui-icon">&#xe615;</i></button>
        </div>

      </div>
      <xblock>
       <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <button class="layui-btn" onclick="addUser()"><i class="layui-icon"></i>添加</button>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
          <!--  <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>-->
            <th>公告编码</th>
            <th>公告标题</th>
            <th>公告内容</th>
            <th>发布人</th>
            <th>操作</th>
          </tr>

        </thead>
        <tbody>

        </tbody>
      </table>

      <div class="m-style page">

      </div>
    </div>
    <script>
   /*   layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });*/



      /*用户-删除*/

      function delAll (argument) {

        var data = tableCheck.getData();
  
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>
  </body>

<script>
   $(function () {
     $.ajax({
       url:'/Personnel/notice/queryall1',
       type:'get',
       data:{"pageindex":1},
       dataType:'json',
       success:function (d) {
         //解析--数组对象
         showData(d);
         showInfo(d.rowCount);
       }
     })
   })
   $("#searchbutton").click(function () {
     var title=$("#searchname").val();
     var user_id=$("#searchid").val();
     $.ajax({
       url:'/Personnel/notice/querytitle',
       type:'get',
       data:{"pageindex":1,"title":title,"user_id":user_id},
       dataType:'json',
       success:function (d) {
         showData(d);
         showInfoSearch(d.rowCount);
       }
     })
   })


  function showInfo(d){
    $(".m-style").pagination({
      totalData:d,
      showData:5,
      coping: true,
      homePage: '首页',
      endPage: '末页',
      prevContent: '上页',
      nextContent: '下页',
      callback:function (api) {
        $.ajax({
          url:'/Personnel/notice/queryall1',
          type:'get',
          data:{"pageindex": api.getCurrent()},
          dataType:'json',
          success:function (d) {
            //解析--数组对象

            showData(d);

          },
          error:function () {

          }
        })

      }
    })
  }
  function showInfoSearch(d){
    var title = $("#searchname").val();
    var user_id= $("#searchid").val();
    $(".m-style").pagination({
      totalData:d,
      showData:5,
      coping: true,
      homePage: '首页',
      endPage: '末页',
      prevContent: '上页',
      nextContent: '下页',
      callback:function (api) {
        $.ajax({
          url:'/Personnel/notice/querytitle',
          type:'get',
          data:{"pageindex": api.getCurrent(),"title":title,"user_id":user_id},
          dataType:'json',
          success:function (d) {
            //解析--数组对象
            showData(d);

          }
        })

      }
    })
  }
  function showData(d) {
    var html="";
    $.each(d.list,function(i,notice){
    /*  var date = new Date(notice.joindate).getFullYear()+'-'+new Date(notice.joindate).getMonth()+'-'+new Date(notice.joindate).getDay();*/
      html+="<tr>";
      html+="<td><span>"+notice.id+"</span></td>";
      html+="<td><span>"+notice.title+"</span></td>";
      html+="<td><span>"+notice.content+"</span></td>";
      html+="<td><span>"+notice.user.loginname+"</span></td>";
      html+="<td><span><a class=\"modifyUser\" href=\"noticemodify.html?id="+notice.id+"\"><img src=\"../images/xiugai.png\" alt=\"修改\" title=\"修改\"/></a></span>\n" +
              "            <span><a class=\"deleteUser\"onclick=\"del_notice("+notice.id+")\" href=\"javascript:;\" ><img src=\"../images/schu.png\" alt=\"删除\" title=\"删除\"/></a></span>" +
              "</td>";
      html+="</tr>";
    })
    $("table tr:not(:first)").remove();
    $("table").append(html);
  }
  function del_notice(id){
    var fig = confirm("确定要删除公告吗");
    if(fig){
      $.ajax({
        url:'/Personnel/notice/deletenotice',
        type:'get',
        data:{"id":id},
        dataType:'json',
        success:function (d) {
          if(d.fig=="success"){
            //添加成功
            location.reload();
          }else{
            alert("删除失败!");
          }

        }
      })
    }
  }
  function TimeT(date) {
         var Time = new Date(date);
         var y = Time.getFullYear();
         var m = Time.getMonth();
         m = m<10?('0'+m):m;
         var d = Time.getDate();
         d = d<10?('0'+d):d;
         return y+'-'+m+'-'+d;
  }
  function addUser() {
       window.location.href="noticeadd.html";
  }
</script>
</html>